const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        user: {},
        money: '',
        bank_id:0,
        bank_name:'请选择银行卡',
        bank_cardid:'',
        
    },



    setMoney: function (e) {
        this.setData({
            money: e.detail.value
        })
    },


    // 全部提现
    allMoney: function (e) {
     
        var allmoney = e.target.dataset.allmoney;
        console.log(allmoney);
        this.setData({
            money: allmoney
        })
    },


    //银行卡列表
    bank_list: function (e) {
        wx.redirectTo({
            url: '/pages/bank_list/bank_list'
        })
    },


    // 跳转提现明细
    withdraw_log: function () {
        wx.navigateTo({
            url: '/pages/withdraw_log/withdraw_log'
        })
    },

    

    withdraw: function(){
        var money = parseFloat(this.data.money) || 0;
        money = parseFloat(money.toFixed(2));
        
        if(money < 0.01){
            wx.showToast({
              title: '提现金额错误',
              icon: 'none'
            });
            return false;
        }
        app.ajax({
            url: '/api/user/withdraw',
            data: {
                money: money,
                bank_id:this.data.bank_id,
                type:1
            },
            success: res => {
                if(res.code == 1){
                    console.log(res);
                    wx.showToast({
                        title: res.msg,
                        icon: 'none'
                      })
                }else{
                    wx.showToast({
                      title: res.msg,
                      icon: 'none'
                    })
                }
            }
        }, 1);
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var user = wx.getStorageSync('user') || {};
        var bank_id = options.bank_id;
        var bank_name = options.bank_name;
        var carid = options.carid;
        if(carid){
            carid = carid.slice(carid.length - 4)
        }
    
        console.log(user);
        this.setData({
          user: user,
          bank_name: bank_name,
          carid: carid,
          bank_id: bank_id,
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})